# Maintainer: Alexey Kasatkin <alexeikasatkin@gmail.com>

_realname=stxxl
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=1.4.1.343.gf7389c7
pkgrel=2
pkgdesc="Standard Template Library for Extra Large Data Sets (mingw-w64)"
arch=('any')
url="https://stxxl.sourceforge.io/"
license=('custom:Boost')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake" 'git')
options=('strip' 'staticlibs')
source=("${_realname}"::"git+https://github.com/stxxl/stxxl.git"
        001-cmake-files-location.patch
        002-install-shared-lib.patch)
sha256sums=('SKIP'
            'da0c4dc2e3bf3a1f1978116fde036f2087af8307101e76fe36b773cb5a22a432'
            '00388f16e6f94abf83de444e7b4940e65e4325258a05f4e4a6a2dad79915960b')

pkgver() {
  cd "${_realname}"
  git describe --tags | sed 's|-|.|g'
}

prepare() {
  cd ${_realname}
  patch -p1 -i ${srcdir}/001-cmake-files-location.patch
  patch -p1 -i ${srcdir}/002-install-shared-lib.patch
}

build() {
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DUSE_GNU_PARALLEL=ON \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_STATIC_LIBS=ON \
    ../${_realname}

  make
}


package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install

  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  install -Dm644 ../${_realname}/LICENSE_1_0.txt \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE_1_0.txt"
}
